<?php
/**
 * 信息管理Controller
 * User: Administrator
 * Date: 2016/7/8 0008
 * Time: 上午 10:42
 */
namespace app\controllers;

use app\librarys\BaseController;
use app\librarys\FileService;
use app\librarys\Tools;
use app\models\InstitutionUpdateRecord;
use yii\data\Pagination;
use app\models\Information;
use app\models\Manager;
use app\models\Permission;
use app\models\Institution;
use Yii;

class InfoController extends BaseController
{

    /**
     * 获取机构列表（包括0机构） get-all-institution
     * @return string
     */
    public function actionGetAllInstitution()
    {
        $this->layout = false;

        $childinst = Information::getAllInstitution();

        return $this->renderJson(['childinst' => $childinst]);
    }

    /*************广告************************************************************************************************/
    /**
     * 广告设置 ad
     */
    public function actionAd()
    {
        $page = Yii::$app->request->get('page', 1);//分页起始页默认为1
        $institution_code = Yii::$app->request->get('inst', '');
        $name = Yii::$app->request->get('name', '');
        $is_shown = Yii::$app->request->get('is_shown', '-1');

        //取得产品总数 -用于分页
        $DataCount = 0;
        $PageSize = 10;
        $list = null;

        $currentManager = Manager::getCurrentManager();
        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $institution = $currentManager['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }

        //查询结果
        if ($institution_code != null && $institution_code != '') {
            //查询记录总数
            $DataCount = Information::getAdCountByfilters($institution_code, $name, $is_shown);
            //查询分页列表
            $list = Information::getAdListByfilters($institution_code, $name, $is_shown, $page, $PageSize);
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);


        //返回机构列表用于机构选择控件使用
        $institutions_list = null;
        if (Permission::isSystemAdmin()) {
            $institutions_list = Institution::getAllEnabledListWithHierarchy($currentManager['institution_code']);
        } else {
            $institutions_list = Institution::getAllEnabledSelfChildren($currentManager['institution_code']);
        }

        $hasModifiedInstitutionList = InstitutionUpdateRecord::getHasModifiedInstitutionCodeList(5);

        //返回分页、结果、以及传入的参数值
        return $this->render('ad',
            [
                'pagination' => $pagination,
                'list' => $list,
                'institution_code' => $institution_code,
                'name' => $name,
                'is_shown' => $is_shown,
                'institutions_list' => $institutions_list,
                'has_modified_institution_list' => $hasModifiedInstitutionList
            ]);
    }

    /**
     * 广告新增 编辑 VIEW ad-part-view
     */
    public function actionAdPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getAdDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getAdCategoryAndSYSList($institution_code);

        //返回机构列表用于机构选择控件使用
        $currentManager = Manager::getCurrentManager();
        $institutions_list = null;
        if (Permission::isSystemAdmin()) {
            $institutions_list = Institution::getAllEnabledListWithHierarchy($currentManager['institution_code']);
        } else {
            $institutions_list = Institution::getAllEnabledSelfChildren($institution_code);
        }

        return $this->renderPartial('ad-part-view', ['institution_code' => $institution_code, 'detail' => $detail, 'category' => $categoryList, 'institutions_list' => $institutions_list]);
    }

    /**
     * 广告编辑保存 ad-save
     */
    public function actionAdSave()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("edit_id");
        $institution_code = $request->post("edit_institution_code");
        $name = $request->post("edit_name");
        $category_id = $request->post("edit_category_id");
        $image_url = $request->post("edit_image_url");
        $link_url = $request->post("edit_link_url");
        $description = $request->post("edit_description");
        $is_shown = $request->post("edit_is_shown");


        //读取上传的图片文件
        if (isset($_FILES['edit_image_file'])) {
            if ($_FILES["edit_image_file"]["error"] == 0) {
                $fileName = Tools::uuid() . '.' . pathinfo($_FILES["edit_image_file"]["name"])['extension'];
                $filePath = $_FILES["edit_image_file"]["tmp_name"];
//                $uploadResult = Cosapi::upload($filePath, Conf::BucketName(), Conf::dstPath($fileName));
//                if ($uploadResult['code'] == 0) {
//                    $image_url = $uploadResult['data']['access_url'];
//                }
                $image_url = FileService::uploadImage($filePath, $fileName);
            }
        }


        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存数据 (id为空则为新增不为空则为修改)
            $rtid = Information::adSave($id, $institution_code, $name, $category_id, $image_url, $link_url, $description, $is_shown);

            //保存到修改记录
            if (!InstitutionUpdateRecord::existRecord($institution_code, 5)) {
                InstitutionUpdateRecord::addRecord($institution_code, 5);
            }
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "数据保存失败";
        }

        return $this->renderJson(['id' => $rtid, 'image_url' => $image_url], $flag, $msg);
    }

    /**
     * 广告删除 ad-delete
     */
    public function actionAdDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::adDelete($id);

            //保存到修改记录
            if (!InstitutionUpdateRecord::existRecord($institution_code, 5)) {
                InstitutionUpdateRecord::addRecord($institution_code, 5);
            }
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }

    /*************广告分类******/
    /**
     * 广告分类 ad-category
     */
    public function actionAdCategory()
    {
        $institution_code = Yii::$app->request->get('inst', '');
        $list = null;
        //查询结果
        if ($institution_code == null || $institution_code == '') {
            //列表 （进入页面默认显示系统分类）
            $list = Information::getAdCategoryList('0');
        } else {
            $list = Information::getAdCategoryList($institution_code);
        }

        $currentManager = Manager::getCurrentManager();
        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $institution = $currentManager['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }

        //返回机构列表用于机构选择控件使用
        $institutions_list = null;
        if (Permission::isSystemAdmin()) {
            $institutions_list = Institution::getAllEnabledListWithHierarchy($currentManager['institution_code']);
        } else {
            $institutions_list = Institution::getAllEnabledSelfChildren($currentManager['institution_code']);
        }

        $hasModifiedInstitutionList = InstitutionUpdateRecord::getHasModifiedInstitutionCodeList(6);

        //返回
        return $this->render('ad-category',
            [
                'list' => $list,
                'institution_code' => $institution_code,
                'institutions_list' => $institutions_list,
                'has_modified_institution_list' => $hasModifiedInstitutionList
            ]);
    }

    public function actionSysAdCategoryHandle()
    {
        $request = \Yii::$app->request;
        $current_institution_code = Manager::getCurrentManager()['institution_code'];
        $dest_institution_codes = $request->post('institution_codes');

    }

    /**
     * 广告分类新增 编辑 VIEW ad-category-part-view
     */
    public function actionAdCategoryPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        $category = '';//分类信息
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $category = Information::getAdCategoryDetails($id, $institution_code);
        }

        //返回机构列表用于机构选择控件使用
        $currentManager = Manager::getCurrentManager();
        $institutions_list = null;
        if (Permission::isSystemAdmin()) {
            $institutions_list = Institution::getAllEnabledListWithHierarchy($currentManager['institution_code']);
        } else {
            $institutions_list = Institution::getAllEnabledSelfChildren($institution_code);
        }
        return $this->renderPartial('ad-category-part-view', ['institution_code' => $institution_code, 'category' => $category, 'institutions_list' => $institutions_list]);
    }

    /**
     * 广告分类编辑保存 ad-category-save-handler
     */
    public function actionAdCategorySaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $name = $request->post("name");
        $identifier_code = $request->post("identifier_code");
        $description = $request->post("description");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {

            $adcate = Information::getAdCategoryByKey($institution_code, $id, $identifier_code);

            if ($adcate != null && $adcate != '') {
                $flag = 1;
                $msg = "分类定义标识符不能重复";
            } else {
                //判断是否有相同的名称
                $count = Information::getSameNameCategoryCount($institution_code, $name, $id);
                $continue = true;

                if ($count > 0) {
                    $msg = '系统已经存在相同的广告分类名称';
                    $flag = 1;
                    $continue = false;
                }

                if ($continue) {
                    //保存分类数据 (id为空则为新增不为空则为修改)
                    $rtid = Information::adCategorySave($id, $institution_code, $name, $identifier_code, $description);

                    //保存到修改记录
                    if (!InstitutionUpdateRecord::existRecord($institution_code, 6)) {
                        InstitutionUpdateRecord::addRecord($institution_code, 6);
                    }

                    //没有返回操作的数据ID
                    if ($rtid == null || $rtid == '') {
                        $flag = 1;
                        $msg = "操作失败";
                    }
                }
            }
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 广告分类删除 ad-category-delete
     */
    public function actionAdCategoryDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::adCategoryDelete($id);

            //保存到修改记录
            if (!InstitutionUpdateRecord::existRecord($institution_code, 6)) {
                InstitutionUpdateRecord::addRecord($institution_code, 6);
            }
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }
    /*************广告分类******/
    /*************广告************************************************************************************************/

    /*************新闻咨询********************************************************************************************/
    /**
     * 新闻咨询设置 news
     */
    public function actionNews()
    {
        $page = Yii::$app->request->get('page', 1);//分页起始页默认为1
        $institution_code = Yii::$app->request->get('inst', '');
        $title = Yii::$app->request->get('title', '');
        $is_shown = Yii::$app->request->get('is_shown', '-1');

        //取得产品总数 -用于分页
        $DataCount = 0;
        $PageSize = 10;
        $list = null;

        //查询结果
        if ($institution_code != null && $institution_code != '') {
            //查询记录总数
            $DataCount = Information::getNewsCountByfilters($institution_code, $title, $is_shown);
            //查询分页列表
            $list = Information::getNewsListByfilters($institution_code, $title, $is_shown, $page, $PageSize);
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $session = Yii::$app->session;
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回分页、结果、以及传入的参数值
        return $this->render('news', ['pagination' => $pagination, 'list' => $list,
            'institution_code' => $institution_code, 'title' => $title, 'is_shown' => $is_shown]);
    }

    /**
     * 新闻咨询新增 编辑 VIEW news-part-view
     */
    public function actionNewsPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getNewsDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getNewsCategoryAndSYSList($institution_code);

        return $this->renderPartial('news-part-view', ['institution_code' => $institution_code, 'detail' => $detail, 'category' => $categoryList]);
    }

    /**
     * 新闻咨询新增 编辑 news-edit
     */
    public function actionNewsEdit()
    {
        $id = Yii::$app->request->get('id', '');
        $institution_code = Yii::$app->request->get('inst', '');
        $page = Yii::$app->request->get('page', '');
        $title = Yii::$app->request->get('title', '');
        $is_shown = Yii::$app->request->get('is_shown', '');

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getNewsDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getNewsCategoryAndSYSList($institution_code);

        return $this->render('news-edit', ['institution_code' => $institution_code,
            'page' => $page, 'title' => $title, 'is_shown' => $is_shown, 'id' => $id,
            'detail' => $detail, 'category' => $categoryList]);
    }

    /**
     * 新闻咨询编辑保存 news-save
     */
    public function actionNewsSaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $title = $request->post("title");
        $category_id = $request->post("category_id");
        $content_html = $request->post("content_html");
        $description = $request->post("description");
        $is_shown = $request->post("is_shown");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存数据 (id为空则为新增不为空则为修改)
            $rtid = Information::newsSave($id, $institution_code, $title, $category_id, $content_html, $description, $is_shown);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 新闻咨询删除 news-delete
     */
    public function actionNewsDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::newsDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }

    /*************新闻咨询分类******/
    /**
     * 新闻咨询分类 news-category
     */
    public function actionNewsCategory()
    {
        $institution_code = Yii::$app->request->get('inst', '');
        $list = null;
        //查询结果
        if ($institution_code == null || $institution_code == '') {
            //列表 （进入页面默认显示系统分类）
            $list = Information::getNewsCategoryList('0');
        } else {
            $list = Information::getNewsCategoryList($institution_code);
        }

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $session = Yii::$app->session;
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回
        return $this->render('news-category', ['list' => $list, 'institution_code' => $institution_code]);
    }

    /**
     * 新闻咨询分类新增 编辑 VIEW news-category-part-view
     */
    public function actionNewsCategoryPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        $category = '';//分类信息
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $category = Information::getNewsCategoryDetails($id, $institution_code);
        }
        return $this->renderPartial('news-category-part-view', ['institution_code' => $institution_code, 'category' => $category]);
    }

    /**
     * 新闻咨询分类编辑保存 news-category-save
     */
    public function actionNewsCategorySaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $name = $request->post("name");
        $identifier_code = $request->post("identifier_code");
        $description = $request->post("description");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存分类数据 (id为空则为新增不为空则为修改)
            $rtid = Information::newsCategorySave($id, $institution_code, $name, $identifier_code, $description);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 新闻咨询分类删除 news-category-delete
     */
    public function actionNewsCategoryDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::newsCategoryDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }
    /*************新闻咨询分类******/
    /*************新闻咨询********************************************************************************************/

    /*************通知公告********************************************************************************************/
    /**
     * 通知公告设置 notice
     */
    public function actionNotice()
    {
        $page = Yii::$app->request->get('page', 1);//分页起始页默认为1
        $institution_code = Yii::$app->request->get('inst', '');
        $title = Yii::$app->request->get('title', '');
        $is_shown = Yii::$app->request->get('is_shown', '-1');

        //取得产品总数 -用于分页
        $DataCount = 0;
        $PageSize = 10;
        $list = null;

        //查询结果
        if ($institution_code != null && $institution_code != '') {
            //查询记录总数
            $DataCount = Information::getNoticeCountByfilters($institution_code, $title, $is_shown);
            //查询分页列表
            $list = Information::getNoticeListByfilters($institution_code, $title, $is_shown, $page, $PageSize);
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回分页、结果、以及传入的参数值
        return $this->render('notice', ['pagination' => $pagination, 'list' => $list,
            'institution_code' => $institution_code, 'title' => $title, 'is_shown' => $is_shown]);
    }

    /**
     * 通知公告新增 编辑 VIEW notice-part-view
     */
    public function actionNoticePartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getNoticeDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getNoticeCategoryAndSYSList($institution_code);

        return $this->renderPartial('notice-part-view', ['institution_code' => $institution_code, 'detail' => $detail, 'category' => $categoryList]);
    }

    /**
     * 通知公告新增 编辑 notice-edit
     */
    public function actionNoticeEdit()
    {
        $id = Yii::$app->request->get('id', '');
        $institution_code = Yii::$app->request->get('inst', '');
        $page = Yii::$app->request->get('page', '');
        $title = Yii::$app->request->get('title', '');
        $is_shown = Yii::$app->request->get('is_shown', '');

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getNoticeDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getNoticeCategoryAndSYSList($institution_code);

        return $this->render('notice-edit', ['institution_code' => $institution_code,
            'page' => $page, 'title' => $title, 'is_shown' => $is_shown, 'id' => $id,
            'detail' => $detail, 'category' => $categoryList]);
    }

    /**
     * 通知公告编辑保存 notice-save
     */
    public function actionNoticeSaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $title = $request->post("title");
        $category_id = $request->post("category_id");
        $content_html = $request->post("content_html");
        $description = $request->post("description");
        $is_shown = $request->post("is_shown");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存数据 (id为空则为新增不为空则为修改)
            $rtid = Information::noticeSave($id, $institution_code, $title, $category_id, $content_html, $description, $is_shown);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 通知公告删除 notice-delete
     */
    public function actionNoticeDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::noticeDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }

    /*************通知公告分类******/
    /**
     * 通知公告分类 notice-category
     */
    public function actionNoticeCategory()
    {
        $institution_code = Yii::$app->request->get('inst', '');
        $list = null;
        //查询结果
        if ($institution_code == null || $institution_code == '') {
            //列表 （进入页面默认显示系统分类）
            $list = Information::getNoticeCategoryList('0');
        } else {
            $list = Information::getNoticeCategoryList($institution_code);
        }

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回
        return $this->render('notice-category', ['list' => $list, 'institution_code' => $institution_code]);
    }

    /**
     * 通知公告分类新增 编辑 VIEW notice-category-part-view
     */
    public function actionNoticeCategoryPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        $category = '';//分类信息
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $category = Information::getNoticeCategoryDetails($id, $institution_code);
        }
        return $this->renderPartial('notice-category-part-view', ['institution_code' => $institution_code, 'category' => $category]);
    }

    /**
     * 通知公告分类编辑保存 notice-category-save
     */
    public function actionNoticeCategorySaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $name = $request->post("name");
        $identifier_code = $request->post("identifier_code");
        $description = $request->post("description");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存分类数据 (id为空则为新增不为空则为修改)
            $rtid = Information::noticeCategorySave($id, $institution_code, $name, $identifier_code, $description);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 通知公告分类删除 notice-category-delete
     */
    public function actionNoticeCategoryDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::noticeCategoryDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }
    /*************通知公告分类******/
    /*************通知公告********************************************************************************************/

    /*************友情链接********************************************************************************************/
    /**
     * 友情链接设置 friendly-link
     */
    public function actionFriendlyLink()
    {
        $page = Yii::$app->request->get('page', 1);//分页起始页默认为1
        $institution_code = Yii::$app->request->get('inst', '');
        $name = Yii::$app->request->get('name', '');
        $is_shown = Yii::$app->request->get('is_shown', '-1');

        //取得产品总数 -用于分页
        $DataCount = 0;
        $PageSize = 10;
        $list = null;

        //查询结果
        if ($institution_code != null && $institution_code != '') {
            //查询记录总数
            $DataCount = Information::getFriendlyLinkCountByfilters($institution_code, $name, $is_shown);
            //查询分页列表
            $list = Information::getFriendlyLinkListByfilters($institution_code, $name, $is_shown, $page, $PageSize);
        }

        $pagination = new Pagination([
            'defaultPageSize' => $PageSize,
            'totalCount' => $DataCount,
        ]);

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回分页、结果、以及传入的参数值
        return $this->render('friendly-link', ['pagination' => $pagination, 'list' => $list,
            'institution_code' => $institution_code, 'name' => $name, 'is_shown' => $is_shown]);
    }

    /**
     * 友情链接新增 编辑 VIEW friendly-link-part-view
     */
    public function actionFriendlyLinkPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        //详情
        $detail = '';
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $detail = Information::getFriendlyLinkDetails($id, $institution_code);
        }
        //分类列表
        $categoryList = Information::getFriendlyLinkCategoryAndSYSList($institution_code);

        return $this->renderPartial('friendly-link-part-view', ['institution_code' => $institution_code, 'detail' => $detail, 'category' => $categoryList]);
    }

    /**
     * 友情链接编辑保存 friendly-link-save
     */
    public function actionFriendlyLinkSaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $name = $request->post("name");
        $category_id = $request->post("category_id");
        $link_url = $request->post("link_url");
        $is_shown = $request->post("is_shown");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存数据 (id为空则为新增不为空则为修改)
            $rtid = Information::friendlyLinkSave($id, $institution_code, $name, $category_id, $link_url, $is_shown);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 友情链接删除 friendly-link-delete
     */
    public function actionFriendlyLinkDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::friendlyLinkDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }

    /*************友情链接分类******/
    /**
     * 友情链接分类 friendly-link-category
     */
    public function actionFriendlyLinkCategory()
    {
        $institution_code = Yii::$app->request->get('inst', '');
        $list = null;
        //查询结果
        if ($institution_code == null || $institution_code == '') {
            //列表 （进入页面默认显示系统分类）
            $list = Information::getFriendlyLinkCategoryList('0');
        } else {
            $list = Information::getFriendlyLinkCategoryList($institution_code);
        }

        //返回时如果未选择机构则返回当前用户所属机构
        if ($institution_code == null || $institution_code == '') {
            //当前用户的机构-----------------------------------------------
            $current_console_user = Manager::getCurrentManager();
            $institution = $current_console_user['institution_code'];
            //---------------------------------------------------------------
            $institution_code = $institution;
        }
        //返回
        return $this->render('friendly-link-category', ['list' => $list, 'institution_code' => $institution_code]);
    }

    /**
     * 友情链接分类新增 编辑 VIEW friendly-link-category-part-view
     */
    public function actionFriendlyLinkCategoryPartView()
    {
        $request = Yii::$app->request;
        $institution_code = $request->post("institution_code");
        $id = $request->post("id");

        $category = '';//分类信息
        if (($id != null && $id != '') && ($institution_code != null && $institution_code != '')) {
            $category = Information::getFriendlyLinkCategoryDetails($id, $institution_code);
        }
        return $this->renderPartial('friendly-link-category-part-view', ['institution_code' => $institution_code, 'category' => $category]);
    }

    /**
     * 友情链接分类编辑保存 friendly-link-category-save
     */
    public function actionFriendlyLinkCategorySaveHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");
        $institution_code = $request->post("institution_code");
        $name = $request->post("name");
        $identifier_code = $request->post("identifier_code");
        $description = $request->post("description");

        $rtid = "";
        if ($institution_code != null && $institution_code != '') {
            //保存分类数据 (id为空则为新增不为空则为修改)
            $rtid = Information::friendlyLinkCategorySave($id, $institution_code, $name, $identifier_code, $description);
        }

        //没有返回操作的数据ID
        if ($rtid == null || $rtid == '') {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson(['id' => $rtid], $flag, $msg);
    }

    /**
     * 友情链接分类删除 friendly-link-category-delete
     */
    public function actionFriendlyLinkCategoryDeleteHandler()
    {
        $msg = "";
        $flag = 0;
        $request = Yii::$app->request;
        $id = $request->post("id");

        $rtstatus = '';
        if ($id != null && $id != '') {
            //删除数据
            $rtstatus = Information::friendlyLinkCategoryDelete($id);
        }

        if ($rtstatus == 0 || $rtstatus == null || $rtstatus == false) {
            $flag = 1;
            $msg = "操作失败";
        }

        return $this->renderJson([], $flag, $msg);
    }
    /*************友情链接分类******/
    /*************友情链接********************************************************************************************/
}

